//package com.xyz.comsumer.controller;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.RestTemplate;
//
//@RestController
//public class HelloController {
//    @Autowired
//    private LoadBalancerClient loadBalancer;
//    @Autowired
//    private DiscoveryClient discoveryClient;
//    private String serviceName = "service-provider";
//
//    /**
//     * 获取所有服务
//     */
//    @RequestMapping("/services")
//    public Object services() {
//        return discoveryClient.getInstances(serviceName);
//    }
//
//    /**
//     * 从所有服务中选择一个服务（轮询）
//     */
//    @RequestMapping("/discover")
//    public Object discover() {
//        return loadBalancer.choose(serviceName).getUri().toString();
//    }
//
//    @RequestMapping("/hello")
//    public String hello() {
//        ServiceInstance serviceInstance = loadBalancer.choose(serviceName);
//        String callServiceResult = new RestTemplate().getForObject(serviceInstance.getUri().toString() + "/hello", String.class);
//        callServiceResult += ",throw service";
//        return callServiceResult;
//    }
//
//}
